package com.example.classmanageapp.sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

public class MyDatabaseHelper extends SQLiteOpenHelper {

    public static final String CREATE_USERLOGIN = "CREATE TABLE \"tb_userlogin\" (\"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\"username\" TEXT,\"passpword\" TEXT,\"usertype\" TEXT)";
    public static final String CREATE_MSG = "CREATE TABLE \"tb_msg\" (\"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , \"msgtitle\" TEXT, \"msgcontent\" TEXT)";
    public static final String INSERT_USERLOGIN_STU = "INSERT INTO \"tb_userlogin\"(\"id\", \"username\", \"passpword\", \"usertype\") VALUES (1, 'stu1', '123', '0')";
    public static final String INSERT_USERLOGIN_TCH = "INSERT INTO \"tb_userlogin\"(\"id\", \"username\", \"passpword\", \"usertype\") VALUES (2, 'tch1', '123', '1')";


    private Context mContext;

    public MyDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        mContext = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_USERLOGIN);
        db.execSQL(INSERT_USERLOGIN_STU);
        db.execSQL(INSERT_USERLOGIN_TCH);
        db.execSQL(CREATE_MSG);
        Toast.makeText(mContext, "create aaaaaaa", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }
}

